const THREE = require("three");
const ThreeBSP = require('three-js-csg')(THREE)
const express = require('express');
const server = express();
server.use((req, res, next) => {
   res.header('Access-Control-Allow-Origin','*');
   res.header('Access-Control-Allow-Headers', '*');
   res.header('Access-Control-Allow-Methods','*');
   res.header('Allow', 'GET, POST, PATCH, OPTIONS, PUT, DELETE');
   res.header('X-Powered-By','3.2.1')
   res.header('Content-Type', 'application/json;charset=utf-8');
   next();
});
server.get('/list', (req, res) => {
    const names = ['Orange', 'Apricot', 'Apple', 'Plum', 'Pear', 'Pome', 'Banana', 'Cherry', 'Grapes', 'Peach'];
    const list = names.map((name, id) => {
    return {
        id: ++id, 
        name,
        price: Math.ceil(Math.random() * 100)
        };
    });

    res.end(JSON.stringify({ code: 0, data: list, message: ''}));
});
server.get('/three', (req, res) => {
    console.log('11');
    console.log(ThreeBSP);
    let bspUtil = {};
    bspUtil.ThreeBSP = ThreeBSP;
    res.end(JSON.stringify({three:bspUtil}));
});
server.listen(5656, () => {
    console.log('listen at http://localhost:5656/');
});